﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Windows.Input;
using WinFormsApp1.MVC.Model;

namespace WinFormsApp1.MVVM.ViewModel
{

	public class PersonViewModel : INotifyPropertyChanged
	{
		private Person _person;
		private string _message;

		public PersonViewModel()
		{
			_person = new Person();
			SubmitCommand = new RelayCommand(Submit);
		}

		public string Name
		{
			get => _person.Name;
			set
			{
				_person.Name = value;
				OnPropertyChanged(nameof(Name));
			}
		}

		public int Age
		{
			get => _person.Age;
			set
			{
				_person.Age = value;
				OnPropertyChanged(nameof(Age));
			}
		}

		public string Message
		{
			get => _message;
			set
			{
				_message = value;
				OnPropertyChanged(nameof(Message));
			}
		}

		public ICommand SubmitCommand { get; }

		private void Submit()
		{
			Message = $"创建: {Name}, 年龄: {Age}";
		}

		public event PropertyChangedEventHandler PropertyChanged;

		protected void OnPropertyChanged(string propertyName)
		{
			PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
		}
	}

}
